package com.cwj.thread;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @author chenwujie
 * @date 2021-02-24 16:59
 */
public class ProducerConsumerWithAqsTest<E> {
    private BlockingDeque<E> aqs = new LinkedBlockingDeque<>(5);

    public static void main(String[] args) {
        ProducerConsumerWithAqsTest<String> objectProducerConsumerWithAqsTest = new ProducerConsumerWithAqsTest<>();

        objectProducerConsumerWithAqsTest.p("a");
        objectProducerConsumerWithAqsTest.p("b");
        objectProducerConsumerWithAqsTest.p("c");
        objectProducerConsumerWithAqsTest.c();
        objectProducerConsumerWithAqsTest.c();
        objectProducerConsumerWithAqsTest.p("d");
        objectProducerConsumerWithAqsTest.p("e");
        objectProducerConsumerWithAqsTest.p("f");
        objectProducerConsumerWithAqsTest.p("g");
        objectProducerConsumerWithAqsTest.c();
        objectProducerConsumerWithAqsTest.c();
        objectProducerConsumerWithAqsTest.c();
        objectProducerConsumerWithAqsTest.c();
    }

    public void p(E e) {
        aqs.offer(e);
    }

    public void c(){
        E poll = aqs.poll();
        System.out.println("c: " + poll);
    }
}
